filename = "/etc/ansible/spacex-kong"

from ansible.parsing.dataloader import DataLoader
from ansible.vars.manager import VariableManager
from ansible.inventory.manager import InventoryManager


loader = DataLoader()
inventory = InventoryManager(loader=loader, sources="/etc/ansible/spacex-kong")

    

# 获取变量
variable = VariableManager(loader=loader,inventory=inventory)
vars = variable.get_vars()


# 获取所有的主机
hosts = inventory.get_hosts()
# print(hosts)

# list all hosts
hosts = []
hosts += inventory.list_hosts()
# print(hosts)


# list all groups
groups = inventory.list_groups()
# for tag in groups:
#     if tag  != 'all' and tag != 'ungrouped':
#         print("...>",tag)
#         hosts = vars['groups'][tag]
#         # print(hosts)
for tag in groups:
    if tag  == 'all':
        print(hosts)

